package org.springframework.study.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

import java.beans.PropertyDescriptor;

@SuppressWarnings("deprecation")
public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {
	//1 接口方法：实例化bean前进行调用
	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		//1-1 仅对容器中的car-bean 进行处理
		if("car".equals(beanName)){
			System.out.println("InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation()");
		}
		return null;
	}
	//2 接口方法：在实例化bean后进行调用
	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if("car".equals(beanName)){
			System.out.println("InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation()");
		}
		return true;
	}

	// 3 接口方法：在设置某个属性时调用
	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
		//3-1 仅对容器中car-bean进行处理，还可以通过post入参进行过滤，
		//进队car的某个特性进行处理
		if("car".equals(beanName)){
			System.out.println("InstantiationAwareBeanPostProcessor.postProcessPropertyValues");
		}
		return pvs;
	}
}
